package com.wens.monitor.dao;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;

import com.wens.monitor.model.Monitor;
import com.wens.monitor.model.Performancedata;

public class MonitorDAO extends DAO {
	public static Monitor getMonitor(String IP, String processName) {
		Session session = factory.getCurrentSession();
		session.beginTransaction();
		Query q = session.createQuery("from Monitor m where m.server.IP = :IP " +
				"and m.process.name = :processName")
				.setString("processName", processName)
				.setString("IP", IP);
		Object o = q.uniqueResult();
		session.getTransaction().commit();
		if (o != null)
			return (Monitor)o;
		return null;
	}

	public static List<Monitor> listMonitor(String IP) {
		Session session = factory.getCurrentSession();
		session.beginTransaction();
		Query q = session.createQuery("from Monitor m where m.server.IP = :IP")
				.setString("IP", IP);
		List<Monitor> list = q.list();
		session.getTransaction().commit();
		return list;
	}
	
	//TODO delete Monitor
}
